var n;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AudioMgr = undefined;
var BundleConfig = require("AA_BundleConfig");
var ResLoader = require("AA_ResLoader");
var DataManager = require("AA_DataManager");
var LogManager = require("AA_LogManager");
var l = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t._secret_key = "audio";
    t._setting = null;
    return t;
  }
  __extends(t, e);
  Object.defineProperty(t.prototype, "musicOn", {
    get: function () {
      return !this._setting || this._setting.musicOn;
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(t.prototype, "effectOn", {
    get: function () {
      return !this._setting || this._setting.effectOn;
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(t.prototype, "shakeOn", {
    get: function () {
      return !this._setting || this._setting.shakeOn;
    },
    enumerable: false,
    configurable: true
  });
  t.prototype.init = function () {
    var e = this._load("setting");
    this._setting = __assign(__assign({}, {
      music: "",
      musicVolume: 1,
      musicOn: true,
      effectVolume: 1,
      effectOn: true,
      shakeOn: true
    }), e);
    // cccc
    if (window.mg) {
      mg.onHide(function () {
        cc.audioEngine.pauseMusic();
      });
      mg.onShow(function () {
        cc.audioEngine.resumeMusic();
      });
    }
  };
  t.prototype.playMusic = function (e, t, o) {
    undefined === t && (t = true);
    undefined === o && (o = BundleConfig.BundleNames.Audio);
    var n = o + "&" + e;
    if (n != this.currMusic) {
      this.currMusic = n;
      if (!(this._setting.musicVolume <= 0)) {
        this._save("setting", this._setting);
        ResLoader.default.loadRes(o, e, cc.AudioClip).then(function (n) {
          if (n) {
            cc.audioEngine.playMusic(n, t);
          } else {
            LogManager.LogMgr.debug("AudioManager playBgm failed", o, e);
          }
        });
      }
    }
  };
  t.prototype.stopMusic = function () {
    cc.audioEngine.stopMusic();
  };
  t.prototype.lingshiqie = function () { };
  t.prototype.switchMusic = function (e) {
    this._setting.musicOn = e;
    if (e) {
      cc.audioEngine.resumeMusic();
    } else {
      cc.audioEngine.pauseMusic();
    }
    this._save("setting", this._setting);
  };
  t.prototype.setMusicVolume = function (e) {
    this._setting.musicVolume = e;
    cc.audioEngine.setMusicVolume(e);
    this._save("setting", this._setting);
  };
  t.prototype.playEffect = function (e, t, o) {
    undefined === t && (t = false);
    undefined === o && (o = BundleConfig.BundleNames.Audio);
    this._setting.effectVolume <= 0 || ResLoader.default.loadRes(o,  e, cc.AudioClip).then(function (n) {
      if (n) {
        cc.audioEngine.playEffect(n, t);
      } else {
        LogManager.LogMgr.debug("AudioManager playEffect failed", o, e);
      }
    });
  };
  t.prototype.switchEffect = function (e) {
    this._setting.effectOn = e;
    e || cc.audioEngine.stopAllEffects();
    this._save("setting", this._setting);
  };
  t.prototype.setEffectVolume = function (e) {
    this._setting.effectVolume = e;
    cc.audioEngine.setEffectsVolume(e);
    this._save("setting", this._setting);
  };
  t.prototype.switchShake = function (e) {
    this._setting.shakeOn = e;
    this._save("setting", this._setting);
  };
  t.prototype.getSettingInfo = function () {
    return this._setting;
  };
  return t;
}(DataManager.default);
exports.AudioMgr = l.getInstance();